const express = require('express')
const mongoose = require('mongoose')
const config = require('./../config/index')
const app = express()
const bodyParser = require('body-parser')

const articleRouter = require('./../router/articlesRouter')
const userRouter = require('./../router/userRouter')
const carouselRouter = require('./../router/carouselRouter')
mongoose.connect(
  config.mongooseDb,
  {
    useNewUrlParser: true,
    useFindAndModify: true,
    useCreateIndex: true
  },
  err => {
    if (!err) {
      console.log('MongoDB connect successfully')
    } else {
      console.log('MongoDB connect fail')
    }
  }
)
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(express.static('statics')) //指定资源路径
app.use(express.json())
app.use(articleRouter)
app.use(userRouter)
app.use(carouselRouter)
app.get('/', (req, res) => {
  res.send('hello express')
})
app.listen(3000, () => {
  console.log('App listening on port 3000!')
})
